export const isIos = async () => {
  let u = navigator.userAgent;
  let ios = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  let iPhone = u.indexOf("iPhone") > -1 || u.indexOf("Mac") > -1 || u.indexOf("iPad") > -1;
  return ios || iPhone;
};

export const setTitle = (name) => {
  document.title = name || "";
  if (isIos()) {
    const i = document.createElement("iframe");
    i.style.display = "none";
    i.onload = function () {
      setTimeout(function () {
        i.remove();
      }, 9);
    };
    document.body.appendChild(i);
  }
};

export function getCookie(name) {
  const cookies = document.cookie.split("; ");
  for (let i = 0; i < cookies.length; i++) {
    const cookie = cookies[i].split("=");
    if (cookie[0] === name) {
      return cookie[1];
    }
  }
  return "";
}
